package org.andrewwinter.tescopricewar;

public enum Unit
{
    ML("ml"),
    CL("cl"),
    L("L"),
    G("g"),
    KG("kg"),
    PACK("pk"),
    DEFAULT("");

    private final String symbol;

    private Unit(final String symbol)
    {
        this.symbol = symbol;
    }

    public static Unit get(String unit)
    {
        unit = unit.trim();

        if (unit.equalsIgnoreCase("ml"))
            return ML;
        else if (unit.equalsIgnoreCase("cl"))
            return CL;
        else if (unit.equalsIgnoreCase("kg"))
            return KG;
        else if (unit.equalsIgnoreCase("g"))
            return G;
        else if (unit.equalsIgnoreCase("l") || unit.equalsIgnoreCase("ltrs") || unit.equalsIgnoreCase("litres") || unit.equalsIgnoreCase("litre"))
            return L;
        else if (unit.equalsIgnoreCase("pk") || unit.equalsIgnoreCase("pack") || unit.equalsIgnoreCase("S") || unit.equalsIgnoreCase("'S"))
            return PACK;

        throw new RuntimeException("Unknown unit: " + unit);
    }

    public String getSymbol()
    {
        return symbol;
    }
}
